﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Windows.Data;

namespace RestaurantBooker.Controls
{
    public partial class DurationControl : UserControl
    {
        #region Properties
        /// <summary>
        /// The <see cref="Value" /> dependency property's name.
        /// </summary>
        public const string ValuePropertyName = "Value";

        /// <summary>
        /// Gets or sets the value of the <see cref="Value" />
        /// property. This is a dependency property.
        /// </summary>
        public int Value
        {
            get
            {
                return (int)GetValue(ValueProperty);
            }
            set
            {
                SetValue(ValueProperty, value);
            }
        }

        /// <summary>
        /// Identifies the <see cref="Value" /> dependency property.
        /// </summary>
        public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
            ValuePropertyName,
            typeof(int),
            typeof(DurationControl),
            new PropertyMetadata(60, (dp, e) =>
            {
                //TODO: Need check whether exist e.newValue in Duration list - if it does not exist - need add it to ist (in spesial position!!!)
            })); 


        /// <summary>
        /// The <see cref="Step" /> dependency property's name.
        /// </summary>
        public const string StepPropertyName = "Step";

        /// <summary>
        /// Gets or sets the value of the <see cref="Step" />
        /// property. This is a dependency property.
        /// </summary>
        public int Step
        {
            get
            {
                return (int)GetValue(StepProperty);
            }
            set
            {
                SetValue(StepProperty, value);
            }
        }

        /// <summary>
        /// Identifies the <see cref="Step" /> dependency property.
        /// </summary>
        public static readonly DependencyProperty StepProperty = DependencyProperty.Register(
            StepPropertyName,
            typeof(int),
            typeof(DurationControl),
            new PropertyMetadata(15, (dp, e) =>
                {
                    var dc = dp as DurationControl;
                    if (dc != null)
                    {
                        dc.RefreshDurations();
                    }
                }));


        /// <summary>
        /// Maximu meal duration
        /// </summary>
        public int MaxDuration { get; set; }


        /// <summary>
        /// list of durations f meal in minutes
        /// </summary>
        public ObservableCollection<int> Durations { get; private set; }



        #endregion


        private void RefreshDurations()
        {
            Durations.Clear();
            int value = Step;
            while (value <= MaxDuration)
            {
                Durations.Add(value);
                value += Step;
            }
        }

        public DurationControl()
        {
            MaxDuration = 12 * 60; // default Maximum duration value is 12 hours
            Durations = new ObservableCollection<int>();

            InitializeComponent();

            Self.DataContext = this;
            RefreshDurations();

            //durationComboBox.SetBinding(ComboBox.ItemsSourceProperty, new Binding() { Source = this, Path = new PropertyPath("Durations"), Mode = BindingMode.TwoWay });                        
            
        }
    }
}
